<template>
    <el-container style="height: 100%;">
        <el-header>
            <el-row :gutter="20" style="color:#000">
                <el-col :span="12">
                    <div style="font-size: 20px; font-weight: 900;height: 60px;display: flex;align-items: center;">
                        <img src="static/img/login-logo.png" alt="" style="width: 45px;height: 45px;margin-right: 15px;">
                        <div style="display: flex;flex-direction: column;">
                            <span>美易通</span>
                            <span style="font-size: 12px">v{{appVersion}}</span>
                        </div>
                    </div>
                </el-col>
                <el-col :span="12">
                    <div style="float: right;display: flex;align-items: center;height: 60px">
                        <headImg :imgUrl="admin.headimg" size="50"></headImg>
                        <el-dropdown>
                            <span style="margin-left:10px; cursor: pointer">
                        {{admin.name}}<i class="el-icon-arrow-down el-icon--right"></i>
                      </span>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item @click.native="editAdmin">个人信息</el-dropdown-item>
                                <el-dropdown-item @click.native="changePassword">更改密码</el-dropdown-item>
                                <el-dropdown-item @click.native="quit" id="zhuxiao">注销</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </el-col>
            </el-row>
        </el-header>
        <el-container>
            <el-aside width="200px" style="background-color: rgb(84, 92, 100)">
                <el-menu router background-color="#545c64" text-color="#fff">
                    <el-submenu index="12">
                        <template slot="title"><i class="el-icon-h-bumen"></i>分店管理</template>
                        <el-menu-item index="/organization/shopList">分店列表</el-menu-item>
                    </el-submenu>
                    <el-submenu index="1">
                        <template slot="title"><i class="el-icon-h-bumen"></i>基础管理</template>
                        <el-menu-item index="/organization/positionList">职位职称</el-menu-item>
                        <el-menu-item index="/organization/userList2">员工列表</el-menu-item>
                    </el-submenu>
                    <el-submenu index="2">
                        <template slot="title"><i class="el-icon-h-guke1"></i>品牌管理</template>
                        <el-menu-item index="/organization/factoryList">合作厂商</el-menu-item>
                        <el-menu-item index="/organization/brandList">品牌列表</el-menu-item>
                    </el-submenu>
                    <el-submenu index="3">
                        <template slot="title"><i class="el-icon-h-wendang"></i>品相管理</template>
                        <el-menu-item index="/organization/categorylist">品项分类</el-menu-item>
                        <el-menu-item index="/organization/subjectList2">项目列表</el-menu-item>
                        <el-menu-item index="/organization/goodsList">产品列表</el-menu-item>
                    </el-submenu>
                    <!-- <el-submenu index="5">
                        <template slot="title"><i class="el-icon-h-kaidan"></i>经营管理</template>
                        <el-menu-item index="/orderList">修改单据</el-menu-item>
                    </el-submenu> -->
                    <el-submenu index="8">
                        <template slot="title"><i class="el-icon-h-liushi1"></i>库存管理</template>
                        <el-menu-item index="/organization/stockList">出入库管理</el-menu-item>
                        <el-menu-item index="/organization/stockGoodslist">库存统计</el-menu-item>
                    </el-submenu>
                    <el-submenu index="9">
                        <template slot="title"><i class="el-icon-h-chakan"></i>权限管理</template>
                        <el-menu-item index="/organization/permissionLevel/1">权限等级</el-menu-item>
                        <el-menu-item index="/organization/groupAdminlist">账号权限</el-menu-item>
                    </el-submenu>
                    <el-submenu index="10">
                        <template slot="title"><i class="el-icon-h-set2"></i>基础设置</template>
                        <el-menu-item index="/organization/vipgradeList">会员等级</el-menu-item>
                        <el-menu-item index="/organization/diagnosisList">会员诊断</el-menu-item>
                        <el-menu-item index="/organization/guestCategoryList">客户分类</el-menu-item>
                        <el-menu-item index="/organization/guestThreephase">会员三期</el-menu-item>
                        <el-menu-item @click="openMiniProgram">小程序设置</el-menu-item>
                        <el-menu-item index="/organization/subprochildclassList">项目&产品子类</el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main style="background-color: #F0F3F3">
                <transition name="fade" mode="out-in">
                    <router-view></router-view>
                </transition>
            </el-main>
        </el-container>
    </el-container>
  </el-container>
</template>
<script>
import C from '@/common/common.js'
import Setting from '@/service/shop/setting.js'
import headImg from '@/components/headImg.vue'
import { ipcRenderer } from 'electron'
export default {
  name: 'app',
  data () {
    return {
      admin: { headimg: '' },
      appVersion: ''

    }
  },
  methods: {
    openSetting () {
      Setting.openSetting()
    },
    async getAdminInfo () {
      let data = await C.ajax('/shop/index/getadmininfo', {}, 'post')
      this.admin = data.ainfo
      C.setLocalStorage('initConfig', JSON.stringify(data.initConfig))
    },
    async editAdmin () {
      await C.openBrowserWindow('/adminEdit', {}, {
        transparent: true,
        frame: false,
        // openDevTools: true,
        width: 390,
        height: 600,
        useSpa: false,
        spaModel: 'organization'
      })
    },
    async changePassword () {
      let res = await C.openBrowserWindow('/adminChangepas', {}, {
        transparent: true,
        frame: false,
        // openDevTools: true,
        width: 390,
        height: 280,
        useSpa: false,
        spaModel: 'organization'
      })
      if (res) {
        C.success(res.data.info)
      }
    },
    quit () {
      C.confirm('确定要退出吗？', async () => {
        await C.ajax('/login/public/logout', {}, 'post')
        C.setLocalStorage('permission')
        C.setLocalStorage('initConfig')
        C.setLocalStorage('usertoken')
        ipcRenderer.send('zhuxiao')
      })
    },
    checkBigVersion (v1, v2) {
      v1 = v1.split('.')
      v2 = v2.split('.')
      // 先用文字描述逻辑
      // 首先如果主版本1大于主版本2，说明1大
      // 如果主版本1等于主版本2 继续往下比较
      let i = 0
      let len = v1.length
      while (i < len) {
        if (Number(v1[i]) === Number(v2[i])) {
          i++
          continue
        }
        return Number(v1[i]) > Number(v2[i])
      }
      return false
    },
    getVersion () {
      // let config = require('')
      const pack = require('../../../../package.json')
      let version = pack.version
      let smallVersion = pack.smallVersion
      return this.checkBigVersion(version, smallVersion) ? version : smallVersion
    },
    openMiniProgram () {
      C.openBrowserWindow('/orgMiniProgram', {}, {
        width: 900,
        height: 600
      })
    }
  },
  mounted: function () {
    this.getAdminInfo()
    this.appVersion = this.getVersion()
  },
  components: { headImg }
}
</script>